home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
term
/
term34Source.lha
/
SoundPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
15KB
|
547 lines
/*
** SoundPanel.c
**
** Editing panel for sound configuration
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_BELL, GAD_SELECT_BELL,
GAD_CONNECT, GAD_SELECT_CONNECT,
GAD_DISCONNECT, GAD_SELECT_DISCONNECT,
GAD_GOOD_TRANSFER, GAD_SELECT_GOOD_TRANSFER,
GAD_BAD_TRANSFER, GAD_SELECT_BAD_TRANSFER,
GAD_RING, GAD_SELECT_RING,
GAD_VOICE, GAD_SELECT_VOICE,
GAD_PRELOAD,
GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
STATIC struct Gadget *
CreateAllGadgets(struct SoundConfig *Config,struct Gadget *GadgetArray[],struct Gadget **GadgetList)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_SOUNDPANEL_BELL_GAD,MSG_SOUNDPANEL_VOICE_GAD));
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(STRING_KIND,NULL,30,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_BELL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> BellFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_CONNECT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignBottom, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> ConnectFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_DISCONNECT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> DisconnectFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_GOOD_TRANSFER_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_AlignExtra, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> GoodTransferFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_BAD_TRANSFER_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> BadTransferFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_RING_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_AlignExtra, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> RingFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_VOICE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_LeaveFolder, TRUE,
GTST_MaxChars, 255,
GTST_String, Config -> VoiceFile,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_SOUNDPANEL_PRELOAD_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignCentre, TRUE,
GTCB_Checked, Config -> Preload,
TAG_DONE);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_LOAD_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_USE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignBottom, TRUE,
SZ_GroupCount, 4,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_LOAD_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_SAVE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
TAG_DONE);
}
return(Gadget);
}
BYTE
SoundPanel(struct SoundConfig *Config)
{
STATIC struct Gadget *GadgetArray[GAD_CANCEL + 1];
struct Gadget *GadgetList = NULL;
struct Window *PanelWindow;
STATIC struct SoundConfig BackupConfig;
CopyMem(Config,&BackupConfig,sizeof(struct SoundConfig));
if(CreateAllGadgets(Config,GadgetArray,&GadgetList))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
WA_Top, GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight()) / 2,
WA_Width, SZ_GetWindowWidth(),
WA_Height, SZ_GetWindowHeight(),
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Window -> WScreen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_VANILLAKEY | BUTTONIDCMP | CHECKBOXIDCMP | STRINGIDCMP,
WA_Title, LocaleString(MSG_SOUNDPANEL_SOUND_PREFERENCES_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG IClass,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
STRPTR DummyChar;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
struct FileRequester *FileRequest;
GuideContext(CONTEXT_SOUND);
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
ActiveGadget = NULL;
ClrSignal(SIG_BREAK);
while(!Terminated)
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
break;
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
IClass = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(IClass == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
ActiveGadget = Gadget;
}
if(IClass == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(IClass == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_USE:
Terminated = TRUE;
memset(Config,0,sizeof(struct SoundConfig));
strcpy(Config -> BellFile, SZ_GetString(GadgetArray[GAD_BELL]));
strcpy(Config -> ConnectFile, SZ_GetString(GadgetArray[GAD_CONNECT]));
strcpy(Config -> DisconnectFile, SZ_GetString(GadgetArray[GAD_DISCONNECT]));
strcpy(Config -> GoodTransferFile, SZ_GetString(GadgetArray[GAD_GOOD_TRANSFER]));
strcpy(Config -> BadTransferFile, SZ_GetString(GadgetArray[GAD_BAD_TRANSFER]));
strcpy(Config -> RingFile, SZ_GetString(GadgetArray[GAD_RING]));
strcpy(Config -> VoiceFile, SZ_GetString(GadgetArray[GAD_VOICE]));
Config -> Preload = SZ_GetChecked(GadgetArray[GAD_PRELOAD]);
SoundChanged = memcmp(&BackupConfig,Config,sizeof(struct SoundConfig));
break;
case GAD_CANCEL:
Terminated = TRUE;
break;
case GAD_LOAD:
strcpy(DummyBuffer,LastSound);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
BlockWindow(PanelWindow);
if(FileRequest = GetFile(LocaleString(MSG_SOUNDPANEL_LOAD_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
{
if(!ReadIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
MyEasyRequest(Window,LocaleString(MSG_SOUNDPANEL_COULD_NOT_LOAD_SOUNDS_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
else
{
SoundChanged = FALSE;
strcpy(LastSound,DummyBuffer);
GT_SetGadgetAttrs(GadgetArray[GAD_BELL],PanelWindow,NULL,
GTST_String,Config -> BellFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CONNECT],PanelWindow,NULL,
GTST_String,Config -> ConnectFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_DISCONNECT],PanelWindow,NULL,
GTST_String,Config -> DisconnectFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_GOOD_TRANSFER],PanelWindow,NULL,
GTST_String,Config -> GoodTransferFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_BAD_TRANSFER],PanelWindow,NULL,
GTST_String,Config -> BadTransferFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_RING],PanelWindow,NULL,
GTST_String,Config -> RingFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_VOICE],PanelWindow,NULL,
GTST_String,Config -> VoiceFile,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PRELOAD],PanelWindow,NULL,
GTCB_Checked,Config -> Preload,
TAG_DONE);
}
FreeAslRequest(FileRequest);
}
ReleaseWindow(PanelWindow);
break;
case GAD_SAVE:
strcpy(DummyBuffer,LastSound);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
BlockWindow(PanelWindow);
if(FileRequest = GetFile(LocaleString(MSG_SOUNDPANEL_SAVE_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
{
STATIC struct SoundConfig DummyConfig;
memset(&DummyConfig,0,sizeof(struct SoundConfig));
strcpy(DummyConfig . BellFile, SZ_GetString(GadgetArray[GAD_BELL]));
strcpy(DummyConfig . ConnectFile, SZ_GetString(GadgetArray[GAD_CONNECT]));
strcpy(DummyConfig . DisconnectFile, SZ_GetString(GadgetArray[GAD_DISCONNECT]));
strcpy(DummyConfig . GoodTransferFile, SZ_GetString(GadgetArray[GAD_GOOD_TRANSFER]));
strcpy(DummyConfig . BadTransferFile, SZ_GetString(GadgetArray[GAD_BAD_TRANSFER]));
strcpy(DummyConfig . RingFile, SZ_GetString(GadgetArray[GAD_RING]));
strcpy(DummyConfig . VoiceFile, SZ_GetString(GadgetArray[GAD_VOICE]));
DummyConfig . Preload = SZ_GetChecked(GadgetArray[GAD_PRELOAD]);
if(!WriteIFFData(DummyBuffer,&DummyConfig,sizeof(struct SoundConfig),ID_SOUN))
MyEasyRequest(Window,LocaleString(MSG_SOUNDPANEL_COULD_NOT_SAVE_SOUNDS_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
else
{
strcpy(LastSound,DummyBuffer);
SoundChanged = FALSE;
}
FreeAslRequest(FileRequest);
}
ReleaseWindow(PanelWindow);
break;
case GAD_PRELOAD:
break;
default:
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
{
if(Code != '\t')
{
STRPTR Name = SZ_GetString(Gadget);
if(Name[0])
{
struct SoundInfo *SoundInfo;
BlockWindow(PanelWindow);
if(SoundInfo = LoadSound(Name,FALSE))
{
PlaySound(SoundInfo);
FreeSound(SoundInfo);
}
ReleaseWindow(PanelWindow);
}
}
}
else
{
LONG Selection = Gadget -> GadgetID - 1;
BlockWindow(PanelWindow);
strcpy(SharedBuffer,SZ_GetString(GadgetArray[Selection]));
if(FilePart(SharedBuffer) == SharedBuffer)
SharedBuffer[0] = 0;
else
{
DummyChar = PathPart(SharedBuffer);
*DummyChar = 0;
}
DummyChar = FilePart(SZ_GetString(GadgetArray[Selection]));
if(FileRequest = GetFile(LocaleString(MSG_SOUNDPANEL_SELECT_BELL_TXT + (Selection / 2)),SharedBuffer,DummyChar,SharedBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
GT_SetGadgetAttrs(GadgetArray[Selection],PanelWindow,NULL,
GTST_String,SharedBuffer,
TAG_DONE);
FreeAslRequest(FileRequest);
}
ReleaseWindow(PanelWindow);
}
break;
}
}
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeGadgets(GadgetList);
return((BYTE)memcmp(&BackupConfig,Config,sizeof(struct SoundConfig)));
}